import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebPage6 extends StatefulWidget {
  const WebPage6({super.key});

  @override
  State<WebPage6> createState() => _WebPage6State();
}

class _WebPage6State extends State<WebPage6> {
  // 1
  late WebViewController controller;

  @override
  void initState() {
    super.initState();
    _initWebView();
  }

  _initWebView() async {
    // 2
    controller = WebViewController();
    controller.loadRequest(Uri.parse("https://www.bilibili.com/"));
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        WebViewWidget(controller: controller),
        ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (BuildContext context) {
                  return Scaffold(
                    appBar: AppBar(title: const Text('WebPage6')),
                    body: const WebPage6(),
                  );
                },
              ),
            );
          },
          child: const Text('跳转'),
        ),
      ],
    );
  }
}
